from flask import Flask, flash, redirect, render_template, request, url_for

app = Flask(__name__)
app.secret_key = '123456'

@app.route('/')
def index():
    return '<h2>welcome to my app</h2><br/> <a href="/login">login</a>'


@app.route('/login', methods=['GET', 'POST'])
def login():
    error = None
    if request.method == 'POST':
        if request.form['username'] != 'admin' or request.form['password'] != '123456':
            error = 'Invalid username or password. Please try again!'
        else:
            flash('You were successfully logged in')
            return redirect(url_for('index'))
    return render_template('login.html', error=error)
    # return render_template('login.html', error=error)


if __name__ == '__main__':
    app.run(debug=True)